/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.peopleinformation.peopleassesteam.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.peopleinformation.peopleassesteam.entity.PeopleAssessTeam;
import com.jeeplus.modules.peopleinformation.peopleassesteam.mapper.PeopleAssessTeamMapper;

/**
 * 领导班子考核信息Service
 * @author 刘明星
 * @version 2021-09-03
 */
@Service
@Transactional(readOnly = true)
public class PeopleAssessTeamService extends CrudService<PeopleAssessTeamMapper, PeopleAssessTeam> {

	public PeopleAssessTeam get(String id) {
		return super.get(id);
	}
	
	public List<PeopleAssessTeam> findList(PeopleAssessTeam peopleAssessTeam) {
		return super.findList(peopleAssessTeam);
	}
	
	public Page<PeopleAssessTeam> findPage(Page<PeopleAssessTeam> page, PeopleAssessTeam peopleAssessTeam) {
		String organizationLevel = peopleAssessTeam.getOrganizationLevel();
		String ticket = peopleAssessTeam.getTicket();

		if(organizationLevel != null && organizationLevel.indexOf(",") != -1){
			String[] split = organizationLevel.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleAssessTeam.setOrganizationLevellist(arrayList);
		}else if(organizationLevel != null && organizationLevel.indexOf(",") == -1){
			String[] split = new String[]{organizationLevel};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleAssessTeam.setOrganizationLevellist(arrayList);
		}


		return super.findPage(page, peopleAssessTeam);
	}
	
	@Transactional(readOnly = false)
	public void save(PeopleAssessTeam peopleAssessTeam) {
		super.save(peopleAssessTeam);
			/*
			createData 新增
			deleteData 删除
			status 1 是增加   2 是删除   0 是增加和删除
		 */
		if (peopleAssessTeam.getStatus() != null) {
			switch (peopleAssessTeam.getStatus()) {
				case 0:
					String[] split = peopleAssessTeam.getCreateData().split(",");
					for (String i : split) {
						mapper.creatData(i, peopleAssessTeam);
					}
					String[] split3 = peopleAssessTeam.getDeleteData().split(",");
					for (String i : split3) {
						mapper.deleteData(i, peopleAssessTeam.getRemarks());
					}
					break;
				case 1:
					String[] split1 = peopleAssessTeam.getCreateData().split(",");
					for (String i : split1) {
						mapper.creatData(i, peopleAssessTeam);
					}
					break;
				case 2:
					String[] split2 = peopleAssessTeam.getDeleteData().split(",");
					for (int i = 0; i < split2.length; i++) {
						mapper.deleteData(split2[i], peopleAssessTeam.getRemarks());
					}
//				for (String i: split2) {
//					mapper.deleteData(i,peopleAssessInformation);
//				}
					break;
				default:
					System.out.println("不进行任何操作");
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(String id, String ticketCount) {
		super.mapper.delete(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteSchoolleaderLeadership(String id, String ticketCount) {
		super.mapper.deleteSchoolleaderLeadership(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteSamelevelLeadership(String id, String ticketCount) {
		super.mapper.deleteSamelevelLeadership(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteCrowdLeadershipTeach(String id, String ticketCount) {
		super.mapper.deleteCrowdLeadershipTeach(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteCrowdLeadershipFu(String id, String ticketCount) {
		super.mapper.deleteCrowdLeadershipFu(id, ticketCount);
	}
	@Transactional(readOnly = false)
	public void deleteServiceFu(String id, String ticketCount) {
		super.mapper.deleteServiceFu(id, ticketCount);
	}
	
}